﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace SQLTouch.Service.DataContracts
{
    [DataContract]
    public class PredicateData : IEquatable<PredicateData>
    {
        [DataMember]
        private readonly string left;
        [DataMember]
        private readonly PredicateOperator op;
        [DataMember]
        private readonly string right;

        public string Left
        {
            get { return left ?? string.Empty; }
        }

        public PredicateOperator Op
        {
            get { return op; }
        }

        public string Right
        {
            get { return right ?? string.Empty; }
        }

        private PredicateData()
        {

        }

        public PredicateData(string left, PredicateOperator op, string right)
        {
            this.left = left;
            this.op = op;
            this.right = right;
        }

        public bool Equals(PredicateData other)
        {
            return this.Left == other.Left && this.Op == other.Op && this.Right == other.Right;
        }

        public override int GetHashCode()
        {
            return this.Left.GetHashCode() ^ this.Op.GetHashCode() ^ this.Right.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            if (obj is PredicateData)
            {
                return Equals((PredicateData)obj);
            }
            else
            {
                return false;
            }
        }

        public static bool operator ==(PredicateData left, PredicateData right)
        {
            return left.Equals(right);
        }

        public static bool operator !=(PredicateData left, PredicateData right)
        {
            return !(left == right);
        }
    }
}
